<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 矩阵置零 -->
    <script>
      var setZeroes = function (matrix) {
        var row = matrix.length
        var col = matrix[0].length
        var map1 = {}
        var map2 = {}
        for (var i = 0; i < row; i++) {
          for (var j = 0; j < col; j++) {
            if (matrix[i][j] === 0) {
              map1[i] = i
              map2[j] = j
            }
          }
        }
        for (var i in map1) {
          for (var j = 0; j < col; j++) {
            matrix[i][j] = 0
          }
        }
        for (var i in map2) {
          for (var j = 0; j < row; j++) {
            matrix[j][i] = 0
          }
        }
        return matrix
      }
      console.log(
        setZeroes([
          [1, 1, 1],
          [1, 0, 1],
          [1, 1, 1]
        ])
      )
    </script>
  </body>
</html>
